<?php

namespace app\common\model;

use think\Model;
use app\common\model\UnifiedOrder;
class Order extends Model
{
    protected $autoWriteTimestamp =true;
    protected $type = [
        
        'create_time'  =>  'timestamp:Y/m/d H:i:s',
        'update_time'  =>  'timestamp:Y/m/d H:i:s',
    
    ];
    
//    public function getStatusAttr($value){
//        $arr = [0=>'待付款',1=>'待发货',2=>'待收货',5=>'待评价',6=>'退款/售后',-1=>'为订单失败'];
//        return $arr[$value];
//    }
    
    public function getSendStatusAttr($value){
        $arr = [0=>'等待支付',1=>'待发货',2=>'已发货',3=>'正在配送',4=>'已配送',-1=>'配送失败'];
        return $arr[$value];
    }
    
    public function module(){
        return $this->hasOne('Module','id','mid');
    }
    
    public function unifiedOrder(){
        return $this->hasOne('UnifiedOrder','order_id','id');
    }
    
    //
    public function purchaser(){
        return $this->hasMany('Purchaser','order_id','id');
    }
    
    public function member(){
        return $this->hasOne('Member','id','user_id')->field('id,nickname,headimgurl,phone');
    }
    
    public function pay(){
        return $this->hasManyThrough('Pay','UnifiedOrder','out_trade_no','order_id','id');
    }
    
    
    
    
}
